//
//  ExercisesPaperResultModel.m
//  ShowYork
//
//  Created by hxh on 2020/9/10.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "ExercisesPaperResultModel.h"

@implementation ExercisesPaperResultModel
- (CGFloat)celHeight{
    
    // 获取文字高度
    CGSize mainTitleSize = [RPAppManager getTextSizeWithText:self.paper.name font:[UIFont boldSystemFontOfSize:26] maxSize:CGSizeMake(kScreenW - 45 * 2, MAXFLOAT)];
    CGFloat mainTitleH = ceil(mainTitleSize.height);
    // 设置文字和分数之间的间距
    CGFloat scoreMargin = 24;
    // 获取文字高度
    CGSize scoreSize = [RPAppManager getTextSizeWithText:self.paper.score font:[UIFont boldSystemFontOfSize:40] maxSize:CGSizeMake(kScreenW - scoreMargin, MAXFRAG)];
    CGFloat scoreH = ceil(scoreSize.height);
    // 获取下标默认高度
    CGFloat scoreLine = 14;
    // 子标本和下标间距
    CGFloat subMargin = 12;
    // 获取子标题的文字高度
    CGSize subSize = [RPAppManager getTextSizeWithText:@"满分100分 [可作答90分]" font:font(12) maxSize:CGSizeMake(kScreenW - 28, MAXFRAG)];
    CGFloat subH = ceil(subSize.height);
    // 获取用时间距
    CGFloat timeMargin = 24.0f;
    // 获取用时间的高度
    CGSize timeSize = [RPAppManager getTextSizeWithText:@"交卷时间：2020.07.12 13:41" font:font(12) maxSize:CGSizeMake(MAXFRAG, MAXFRAG)];
    CGFloat timeH = ceil(timeSize.height);
    // 加入虚线的高度
    CGFloat dashMargin = 24.0f;
    CGFloat dashLineH = 2.0;
    // 加入答题卡的高度
    CGFloat cardMargin = 24.0f;
    CGSize cardSize = [RPAppManager getTextSizeWithText:@"答题卡" font:[UIFont boldSystemFontOfSize:18] maxSize:CGSizeMake(kScreenW, MAXFRAG)];
    CGFloat cardH = ceil(cardSize.height);
    // 获取底部间距
    CGFloat bottom = 8.0f;
    
    // 计算总高度
    CGFloat totalH = mainTitleH + scoreMargin + scoreH + scoreLine + subMargin + subH + timeMargin + timeH + dashLineH + dashMargin + cardMargin + cardH + bottom + 32;
    
    return totalH;
}
- (void)setAnswer:(ExercisesAnswerPageModel *)answer{
    _answer = answer;
    
    for (ExercisesTitleModel *obj in self.paper.titleItems) {
        [obj.questionItems enumerateObjectsUsingBlock:^(ExercisesQuqestionModel * _Nonnull questionItem, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.answer.answerItems enumerateObjectsUsingBlock:^(ExercisesAnswerItemModel * _Nonnull answerItem, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([answerItem.questionId isEqualToNumber:questionItem.id]) {
                    questionItem.answerItem = answerItem;
                }
            }];
        }];
    }
}


- (NSMutableArray *)resultArray{
    NSMutableArray *resArr = [NSMutableArray array];
    for (ExercisesTitleModel *obj in self.paper.titleItems) {
        NSMutableArray *dataArr = [NSMutableArray array];
        [obj.questionItems enumerateObjectsUsingBlock:^(ExercisesQuqestionModel * _Nonnull questionItem, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.answer.answerItems enumerateObjectsUsingBlock:^(ExercisesAnswerItemModel * _Nonnull answerItem, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([answerItem.questionId isEqualToNumber:questionItem.id]) {
                    questionItem.answerItem = answerItem;
                    *stop = YES;
                }
            }];
            [dataArr addObject:questionItem];
        }];
        [resArr addObject:dataArr];
    }    
    return resArr;
}
@end
